﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Portal.Xml.Utility;

namespace Portal.Workflow.Model
{
    public class WorkflowHasSentCls
    {
        public string WorkflowHasSentId;
        public string WorkflowDefId;
        public string WorkflowDefName;
        public string Subject;
        public string Description;
        public DateTime SentDate;
        public string SendToUsers;
        public string Comment;
    }

    public class WorkflowHasSentParser
    {
        public static WorkflowHasSentCls CreateInstance()
        {
            //tao 1 class trang....
            WorkflowHasSentCls oWorkflowHasSentCls = new WorkflowHasSentCls();
            return oWorkflowHasSentCls;
        }

        public static WorkflowHasSentCls ParseFromXml(string XmlData)
        {
            DataSet ds = XmlUtility.GetDataSetFromXml(XmlData);
            WorkflowHasSentCls oWorkflowHasSentCls = ParseFromDataRow(ds.Tables[0].Rows[0]);
            return oWorkflowHasSentCls;
        }


        public static WorkflowHasSentCls ParseFromDataRow(DataRow dr)
        {
            WorkflowHasSentCls oWorkflowHasSentCls = new WorkflowHasSentCls();

            oWorkflowHasSentCls.WorkflowHasSentId = XmlUtility.GetString(dr, "WorkflowHasSentId", true);
            oWorkflowHasSentCls.WorkflowDefId = XmlUtility.GetString(dr, "WorkflowDefId", true);
            oWorkflowHasSentCls.WorkflowDefName = XmlUtility.GetString(dr, "WorkflowDefName", true);
            oWorkflowHasSentCls.Subject = XmlUtility.GetString(dr, "Subject", true);
            oWorkflowHasSentCls.Description = XmlUtility.GetString(dr, "Description", true);
            oWorkflowHasSentCls.SentDate = (DateTime)dr["SentDate"];
            oWorkflowHasSentCls.SendToUsers = XmlUtility.GetString(dr, "SendToUsers", true);
            oWorkflowHasSentCls.Comment = XmlUtility.GetString(dr, "Comment", true);

            return oWorkflowHasSentCls;
        }

        public static WorkflowHasSentCls[] ParseFromDataTable(DataTable dtTable)
        {
            WorkflowHasSentCls[] SMSItems = new WorkflowHasSentCls[dtTable.Rows.Count];
            for (int iIndex = 0; iIndex < dtTable.Rows.Count; iIndex++)
            {
                SMSItems[iIndex] = ParseFromDataRow(dtTable.Rows[iIndex]);
            }

            return SMSItems;
        }

        public static WorkflowHasSentCls[] ParseMultiRecordFromXml(string XmlData)
        {
            DataSet ds = XmlUtility.GetDataSetFromXml(XmlData);
            if (ds.Tables.Count == 0)
            {
                return new WorkflowHasSentCls[0];
            }
            WorkflowHasSentCls[] SMSItems = new WorkflowHasSentCls[ds.Tables[0].Rows.Count];
            for (int iIndex = 0; iIndex < ds.Tables[0].Rows.Count; iIndex++)
            {
                SMSItems[iIndex] = ParseFromDataRow(ds.Tables[0].Rows[iIndex]);
            }
            return SMSItems;
        }
    }
}

